//
//  LDY_VoiceCollectionViewCell.m
//  VoiceProject
//
//  Created by dlios on 15/11/24.
//  Copyright © 2015年 lulu. All rights reserved.
//

#import "LDY_VoiceCollectionViewCell.h"
#import <SDImageCache.h>
#import <UIImageView+WebCache.h>

#define KWIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define KHEIGHT ([UIScreen mainScreen].bounds.size.height/667)

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@implementation LDY_VoiceCollectionViewCell
-(void)dealloc{
    [_picImageView release];
    [_titleNameLabel release];
    [_channelNameLabel release];
    [_model release];
    [super dealloc];
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picImageView];
        [_picImageView release];
        
        self.titleNameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleNameLabel];
        [_titleNameLabel release];
        
        self.channelNameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.channelNameLabel];
        [_channelNameLabel release];
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.picImageView.frame = CGRectMake(0, 0, WIDTH, HEIGHT / 4 * 3);
    
    self.titleNameLabel.frame = CGRectMake(0, self.picImageView.frame.size.height, WIDTH, HEIGHT / 8);
//    self.titleNameLabel.backgroundColor = [UIColor orangeColor];
    
    self.channelNameLabel.frame = CGRectMake(0, self.picImageView.frame.size.height + self.titleNameLabel.frame.size.height, WIDTH, HEIGHT / 11);
//    self.channelNameLabel.backgroundColor = [UIColor redColor];
}

- (void)setModel:(LDY_VoiceModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"wait"]];
    
    self.titleNameLabel.text = model.name;
    self.titleNameLabel.font = [UIFont systemFontOfSize:14.5 * KWIDTH];
    
    self.channelNameLabel.text = [NSString stringWithFormat:@"%@ 频道", [model.channel objectForKey:@"name"]];
    self.channelNameLabel.textColor = [UIColor grayColor];
    self.channelNameLabel.font = [UIFont systemFontOfSize:12.5 * KWIDTH];
}


@end
